import type { locationDataform } from '@/types/home'
import { defineStore } from 'pinia'
import { ref } from 'vue'
// import type { TokenResult, UserInfoResult } from '@/types/member'

// 定义 Store
export const useDriverLocationCacheStore = defineStore(
  'driverLocationCache',
  () => {
    // 会员信息
    const locationData = ref([] as locationDataform[])

    const getLocationData = () => {
      return locationData.value
    }

    const addLocationData = (val: locationDataform) => {
      locationData.value.push(val)
    }

    const clearLocationData = () => {
      locationData.value = []
    }

    // 记得 return
    return {
      getLocationData,
      addLocationData,
      clearLocationData,
    }
  },
  {
    persist: {
      storage: {
        // ✅ 写入时：附加过期时间
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },

        // ✅ 读取时：检查是否过期
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
